import java.util.Iterator;


public class LineIterator implements Iterator <String>{

    String content = "";
    int index = 0;
    int end = 0;
    int keywordStart = 0;
    int keywordEnd = 0;


    LineIterator ( String content )
    {
        //Set the really long string. (a string of a file usually).
        this.content = content;
    }



    public boolean hasNext() {
        //We have another line if our content isn't empty to begin with and our index isn't -1
        if ( !content.equals("") && index != -1 )
            return true;
        else
            return false;
    }

    //Get next token.
    public String next() {

        //Skip over all tabs and spaces and increase the index (our starting point to search for strings)
        //This finds the first element since any non space and non tab is valid token start.
        while ( content.substring(index, index+1).equals(" ") || content.substring(index, index+1).equals("\t"))
            index++;

        //set the end of the content to the next space otherwise
        //set to to the end of the content

        //Find the next space so we know where the end of the token is.
        end = content.indexOf(" ", index );

        //Find the next tab if there are no more spaces.
        if( end == -1 )
            end = content.indexOf( "\t", index );

        //If there are no tabs either then we have the last
        //token so send the end of our token to the last letter.
        if( end == -1 )
            end = content.length();

        //Set the token start as the current index
        int start = index;
        //Set the index to the end, so we can start from the last letter of this token next time.
        index = end;

        //Set the status if we reached the end of the file.
        if (end == content.length() )
        {
            //Set index to -1 so next time we want to know if we have more tokens we will know -1 means we are done.
            index = -1;
            //Set end to the last letter in the string, we don't want to be off by one.
            end = end -1;
        }
        //Set the beginning and and of the token.
        keywordStart = start;
        keywordEnd = end;

        //Return out token
        return content.substring(start, end);
    }

    //Gets the keyword start within the next... What is this for?
    public int getKeywordStart()
    {
        return keywordStart;
    }

    @Override
    public String toString()
    {
        return ( "index " + index + ", end " + end + ", keywordStart " + keywordStart  + ", keywordEnd " + keywordEnd );
    }

    //What is this for?
    public int getKeywordEnd()
    {
        return keywordEnd;
    }

    //What is this for?
    public void remove() {
        //To change body of implemented methods use File | Settings | File Templates.
    }



}
